package com.ruoyi.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.ExpenseClaim;
import com.ruoyi.project.service.IExpenseClaimService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同报销Controller
 * 
 * @author ruoyi
 * @date 2025-04-06
 */
@RestController
@RequestMapping("/project/claim")
public class ExpenseClaimController extends BaseController
{
    @Autowired
    private IExpenseClaimService expenseClaimService;

    /**
     * 查询合同报销列表
     */
    @PreAuthorize("@ss.hasPermi('project:claim:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExpenseClaim expenseClaim)
    {
        startPage();
        List<ExpenseClaim> list = expenseClaimService.selectExpenseClaimList(expenseClaim);
        return getDataTable(list);
    }

    /**
     * 导出合同报销列表
     */
    @PreAuthorize("@ss.hasPermi('project:claim:export')")
    @Log(title = "合同报销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExpenseClaim expenseClaim)
    {
        List<ExpenseClaim> list = expenseClaimService.selectExpenseClaimList(expenseClaim);
        ExcelUtil<ExpenseClaim> util = new ExcelUtil<ExpenseClaim>(ExpenseClaim.class);
        util.exportExcel(response, list, "合同报销数据");
    }

    /**
     * 获取合同报销详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:claim:query')")
    @GetMapping(value = "/{claimId}")
    public AjaxResult getInfo(@PathVariable("claimId") Long claimId)
    {
        return success(expenseClaimService.selectExpenseClaimByClaimId(claimId));
    }

    /**
     * 新增合同报销
     */
    @PreAuthorize("@ss.hasPermi('project:claim:add')")
    @Log(title = "合同报销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExpenseClaim expenseClaim)
    {
        return toAjax(expenseClaimService.insertExpenseClaim(expenseClaim));
    }

    /**
     * 修改合同报销
     */
    @PreAuthorize("@ss.hasPermi('project:claim:edit')")
    @Log(title = "合同报销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExpenseClaim expenseClaim)
    {
        return toAjax(expenseClaimService.updateExpenseClaim(expenseClaim));
    }

    /**
     * 删除合同报销
     */
    @PreAuthorize("@ss.hasPermi('project:claim:remove')")
    @Log(title = "合同报销", businessType = BusinessType.DELETE)
	@DeleteMapping("/{claimIds}")
    public AjaxResult remove(@PathVariable Long[] claimIds)
    {
        return toAjax(expenseClaimService.deleteExpenseClaimByClaimIds(claimIds));
    }
}
